home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
basic
/
langwn1.exe
/
SAMPLE01.BAS
< prev
next >
Wrap
BASIC Source File
|
1993-03-20
|
38KB
|
1,240 lines
'============================================================================
'============================================================================
' sample code 01 to demonstrate techniques for using LangWin.
' hit Shift+F5 to run this code.
' follow instructions displayed in each sample window.
' you must start QuickBASIC as follows: qb /ah /L langwin
' /L langwin parameter provides access to LangWin quicklib
' /ah parameter is needed to allow dynamic arrays > 64k.
' hit F2, then select one of the demo subroutines to examine sample code
' subroutines called to display sample windows
DECLARE SUB demo1 ()
DECLARE SUB demo2 ()
DECLARE SUB demo3 ()
DECLARE SUB demo4 ()
DECLARE SUB demo5 ()
DECLARE SUB demo6 ()
DECLARE FUNCTION VidType% () ' used to determine type of monitor
' must compile with qb /ah /L langwin
'$DYNAMIC make all arrays dynamic
DEFINT A-Z
'$INCLUDE: 'LANGWIN.BI' ' TYPE, DECLARE and COMMON definitions for LangWin.
' NOTE: LANGWIN.BI contains all definitions found
' in QB.BI, so include for QB.BI is not needed.
CLEAR , , 5000 ' set stack at 5000 bytes
'---------------------------------------------------------------
' first see if EGA or VGA monitor
mm = VidType
IF mm <> 3 AND mm <> 4 THEN
' monitor is not EGA/VGA
' take whatever actions necessary (error messages)
BEEP
PRINT "LangWin needs EGA or VGA, sorry ........"
END
END IF
'-----------------------------------------------------------------
' get attribute from current screen (row 1, col 1)
' so it can be restored upon exit
OrigAttr = SCREEN(1, 1, 1)
'-------------------------------------------------------------------
' if WIDTH command is used, it must be placed before call to LangWinInit
' because code in LangWinInit extracts max rows/cols from screen and saves
' in global variables. if WIDTH is used after LangWinInit, the global
' variable will not be set correctly.
WIDTH 80, 25
'----------------------------------------------------------------------
' these variables MUST be defined BEFORE call to LangWinInit.
' keep these as low as possible to conserve memory at run time.
MaxWindows = 8 ' max simultaneous open windows
MaxButtons = 30 ' max number of objects (incl lines with labels) active
MaxTextLines = 35 ' maximum number of text lines in any scrollable win
MaxTextWins = 5 ' max windows that can have scrollable text
' must be <= MaxWindows
LOCATE , , 0 ' start with hidden text cursor
'---------------------------------------------------------------------------
' LangWin only supports text mode. You MUST call the SCREEN 0 command BEFORE
' the call to LangWinInit. You can call SCREEN with a video page other than 0
' (i.e., SCREEN 0,,x,x where x is a page number supported by your system).
' Code in LangWinInit will determine which video page you are using and save
' the value in a global variable for use by other LangWin routines. If you
' call SCREEN 0 after LangWinInit and change the original video page, you'll
' get unpredictable results (i.e., LangWin will write to the original video
' page). However, you can use other video pages for functions not associated
' with your LangWin windows; just be sure to set the video page back to the
' original value defined below.
SCREEN 0, , 0, 0 ' LangWin ONLY supports text mode
' You MUST call the SCREEN command BEFORE LangWinInit
CALL LangWinInit ' initialize (if mouse exists, it will be displayed)
' if you get "subscript out of range" error while
' in this routine, be sure you called QB with /ah.
' then try reducing the value of MaxWindows.
' check the WIDTH command; reduce number of columns,
' and/or number of rows.
'-----------------------------------------------------------------------
' display "wallpaper"
IF HaveMouse THEN CALL HideMouseCursor ' first hide mouse pointer
CLS
CALL SetColor(8, 15)
FOR i = 1 TO MaxRows
LOCATE i, 1
PRINT STRING$(80, 178); ' can try 176, 177, or 178
NEXT
IF HaveMouse THEN CALL ShowMouseCursor ' display the mouse pointer
'====================================================================
CALL demo1 ' simple window
CALL demo2 ' add window with buttons
CALL demo3 ' add button that causes child window(s) to be opened
CALL demo4 ' window with input fields & child window
CALL demo5 ' scrollable text windows & child windows
CALL demo6 ' password entry technique
'=====================================================================
IF HaveMouse THEN HideMouseCursor ' we're done with the mouse
bbb = (OrigAttr AND &HF0) \ 16 ' mask & shift to get original background
fff = OrigAttr AND &HF ' mask to get original foreground
PALETTE ' restore original palette
CALL SetColor(fff, bbb) ' restore orig foreground/background
CLS
LOCATE , , 1 ' make text cursor visible
END
REM $STATIC
'
' one window opened; it contains info text only.
' no scrollable text, no buttons.
' only valid event is 'close'
' (window can be moved).
'
SUB demo1
'=================================================
' first window: info text only (w1 contains window's number or error code)
w1 = BlankWin(3, 3, 10, 35, 4, 15, 2, 0, 1, 1)
' test to see if window was successfully opened
IF w1 < 0 THEN
' some code to handle the error
CLS
PRINT "w1 BlankWin error number: "; w1
END
END IF
' display some text in the window
d = ShowWinText(2, 2, 0, "Close window to exit")
d = ShowWinText(3, 2, 0, "(double click top/left).")
d = ShowWinText(5, 2, 0, "Drag top/left corner to move.")
' put a title in window
d = ShowTitle("Info Only Window", 15, 1)
' no error tests will be made for above functions
'=============================================================
' MAIN LOOP
' as long as any win is open
' wait for an event in any window, then process it
DO WHILE AnyWinOpen
' wait for an event
' win number (wn) and event code (action) returned
wn = WinEvent(action)
' test window number to see which window was current when event occurred
SELECT CASE wn
CASE w1 ' first window
' now determine what type of event occurred in the window w1
SELECT CASE action
CASE 1 ' close
xx = CloseWindow
CASE 2 ' text
' no scrollable text to select in this win
' this case could be omitted
CASE 3 ' button
' no buttons in this win
' this case could be omitted
END SELECT
END SELECT
LOOP
LOCATE 25, 1
CALL SetColor(15, 4)
PRINT "HIT ANY KEY TO CONTINUE DEMO ...";
SLEEP
LOCATE 25, 1
CALL SetColor(8, 15)
PRINT STRING$(80, 178);
END SUB
'
' this demo adds to the code developed for demo1
'
' two windows opened:
' the first has info text only.
' the second has two buttons:
' 1) beep; 2) exit
'
SUB demo2
'=================================================
' first window: info text only (w1 contains window's number or error code)
w1 = BlankWin(3, 3, 10, 35, 4, 15, 2, 0, 1, 1)
' test to see if window was successfully opened
IF w1 < 0 THEN
' some code to handle the error
CLS
PRINT "w1 BlankWin error number: "; w1
END
END IF
' display some text in the window
d = ShowWinText(2, 2, 0, "Close window to exit")
d = ShowWinText(3, 2, 0, "(double click top/left).")
d = ShowWinText(5, 2, 0, "Drag top/left corner to move.")
' put a title in window
d = ShowTitle("Info Only Window", 15, 1)
' no error tests will be made for above functions
'=============================================================
' second window: text and buttons (w2 contains window's number or error code)
w2 = BlankWin(9, 26, 21, 66, 9, 15, 1, 0, 0, 1)
' test to see if window was successfully opened
IF w2 < 0 THEN
' some code to handle the error
CLS
PRINT "w2 BlankWin error number: "; w2
END
END IF
' display some text in the window
d = ShowWinText(1, 2, 15, "Click button to exit.")
d = ShowWinT